using System;
using System.Collections.Generic;
using System.Linq;
namespace DIS_WEB_Client.Controllers
{
	#region using
	using System.Web.Mvc;
	using DIS_WEB_Client.ViewModels;
	using DIS_WEB_Client.Helpers;
	using System.Web.Security;
    using DIS_Web_Client.DIS_WS_BusinessLayer;
	#endregion
	public partial class AdminController: BaseController
	{
        public ActionResult SelectWeeklyReport()
        {
            var idchemistwarehouse = BusService.Instance.ChemistWareHouse_SelectAll().First(n => n.Name.ToUpper().Contains("ONLINE")).ID;
            var data = new DataTransferViewModel
            {
                IDChemistWareHouse = idchemistwarehouse,
                EnumViewModelType = EnumViewModel.ADMIN_WEEKLYREPORT,
            };
            return View(CreateViewModel(data));
        }

		[ValidateInput(false)]
		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult InsertWeeklyReport(FormCollection forms)
		{
			string idchemistwarehouse = forms.GetValues("WeeklyReport_IDChemistWareHouse")[0];
			string startdate = forms.GetValues("WeeklyReport_StartDate")[0];
			string enddate = forms.GetValues("WeeklyReport_EndDate")[0];
			string note = forms.GetValues("WeeklyReport_Note")[0];
			
            var newItem = new WeeklyReportDTO
			{
				IDChemistWareHouse = int.Parse(idchemistwarehouse),
				StartDate = startdate == "" ? DateTime.Now : DateTime.Parse(startdate),
				EndDate = enddate == "" ? DateTime.Now : DateTime.Parse(enddate),
				Note = note
			};
			
            var result = BusService.Instance.WeeklyReport_Insert(newItem);
			
            var data = new DataTransferViewModel
			{
				IDChemistWareHouse = int.Parse(idchemistwarehouse),
				EnumViewModelType = EnumViewModel.ADMIN_WEEKLYREPORT,
				InfoText = result ? "New item has been added" : "Cannot insert new item"
			};
			return View("SelectWeeklyReport", CreateViewModel(data));
		}

        public ActionResult DetailOfWeeklyReport(int id)
        {
            var data = new DataTransferViewModel
            {
                EnumViewModelType = EnumViewModel.ADMIN_DETAILOF_WEEKLYREPORT,
                IntID = id
            };
            return View(CreateViewModel(data));
        }
	}
}